package colopl.http.util;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class MessageResource {
    
    private static final String FILE_NAME = "colopl-http-client-message";
    
    private static ResourceBundle resourceBundle = ResourceBundle.getBundle(FILE_NAME);
    
    
    
    public static String getMessage(String key) {
        if (key == null) {
            return "[null]:";
        }
        
        StringBuilder sb = new StringBuilder("[");
        sb.append("[");
        sb.append(key);
        sb.append("]");
        sb.append(":");
        try {
            sb.append(resourceBundle.getString(key));
        } catch (MissingResourceException e) {
            sb.append("Can't find the key. key=" + key);
        }
        
        return sb.toString();
    }
    
    public static String getMessage(String key, Object...args) {
        String pattern = getMessage(key);
        
        return MessageFormat.format(pattern, args);
    }
    
}
